package merchant.space;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class Collection {

	private String name;
	private String description;
	private int id;
	private String user;
	private int visibility;
	private String photo;
	private ArrayList<Item> items;
	Bitmap thumb;
	private String cattegory;
	
	public Collection(Collection c)
	{
		name=c.getName();
		description =c.getDescription();
		id=c.getId();
		user=c.getUser();
		visibility=c.getVisibility();
		photo=c.getPhoto();
	}
	
	
	
	public Collection clone() { return new Collection(this); }
	
	public String getPhoto() { return photo; }
	
	public Collection (String n,String d,int i,String u,int vis)
	{
		name=n;
		description=d;
		id=i;
		user=u;
		visibility = vis;
		thumb=null;
	}
	
	public Collection (String n,String d,int vis)
	{
		name=n;
		description=d;
		visibility = vis;
		thumb=null;
	}
	
	public Collection (String n,String d, int vis, String u, String p)
	{
		name=n;
		description=d;
		visibility = vis;
		user=u;
		photo=p;
		thumb=null;
		
	}	
	
	public Collection ()
	{
		
		
	}	
	public Collection (int id,String n,String d, int vis, String u, String p)
	{
		this.id=id;
		name=n;
		description=d;
		visibility = vis;
		user=u;
		photo=p;
		items = new ArrayList<Item>();
		thumb=null;
		
	}	
	
	public Collection (int id,String n,String d, int vis, String u, String p,String cat)
	{
		this.id=id;
		name=n;
		description=d;
		visibility = vis;
		user=u;
		photo=p;
		items = new ArrayList<Item>();
		
		cattegory = cat;
		thumb=getThumb();
		
		
	}	
	
	public String getCattegory(){
		return cattegory;
	}
	
	public void addItem(Item i)
	{
		items.add(i);
	}
	
	public void clearItems()
	{ 	
		items = new ArrayList<Item>();
	}
	
	public Item get(int pos)
	{
		return items.get(pos);
	}
	
	public ArrayList<Item> getItems()
	{
		return items;
	}
	
	public int getVisibility() {
		return visibility;
	}

	public void setVisibility(int v) {
		this.visibility = v;
	}


	public Bitmap getThumb() {
		if (thumb!=null) return thumb;
		else {
        try {
			HttpURLConnection conn = (HttpURLConnection) (new URL(photo)).openConnection();
	        conn.setDoInput(true);	
			conn.connect();
			thumb=  BitmapFactory.decodeStream(conn.getInputStream());
			return thumb;
		} catch (IOException e) {}
		return null;
		}
	}

	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getUser() {
		return user;
	}

	public void setUser(String user) {
		this.user = user;
	}
}
